﻿using CardMaker.Library.Models;

namespace CardMaker.Web.Pages;

public partial class MakeTemplate {
    public IList<CardTemplate> cardTemplates;
    protected override void OnAfterRender(bool firstRender) {
        if (!firstRender)
            return;
        Task.Run(async () => {
            //确实创建了文件夹，但是与数据库不在一个位置，两个位置完全不同

            await _sideImageStorage.InitializeAsync();
            //todo
            await _cardTemplateStorage.InitializeAsync();

            cardTemplates =
                (IList<CardTemplate>) await _cardTemplateService
                    .GetCardTemplatesAsync();
            await InvokeAsync(StateHasChanged);
        });
    }

    private Task<string> GetPath(CardTemplate cardTemplate) {
        var frameimagebox = "FrameImageBox";
        var type = "png";
        var filepath = Path.Combine(
            Environment.GetFolderPath(Environment.SpecialFolder
                .LocalApplicationData), frameimagebox,
            cardTemplate.CardTemplateId + "." + cardTemplate.FrameName + "." +
            type);
        return Task.FromResult(filepath);
    }
}